package zhou.teamwork12;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Q2_ShopmanController {
	
	//-----------商户，添加商品到商店------------
	public boolean addCommodity(Shop s){		
		BaseDao dao=new BaseDao();
		Connection con=dao.getCon();
		String sql="insert into shop (shopName,mark,commodity) value ('"+s.getName()+"','"+s.getMark()+"',?)";
		
		  try{		
		  PreparedStatement ps=con.prepareStatement(sql);
		 // ps.setString(1, s.getCommodity());		
		  ps.executeUpdate();
		  if(ps!=null){
			ps.close();    		   		
		  }
		  if(con!=null){
			con.close();    		   		
		  }		
				
	      }catch(SQLException e){
		     e.printStackTrace();
		}
		return true;
		
		
	}
	
	
	//-----------店主修改，商品的价格，数量，名字-----------------
		public boolean modify(Commodity c){
			   BaseDao bd=new BaseDao();
			   Connection con=bd.getCon();
			   String sql="update Commodity set name =?,price=?,number=? where CommodityId='"+c.getCommodityId()+"'";
			   
			   try {
				PreparedStatement ps=con.prepareStatement(sql);
				ps.setString(1, c.getName());
				ps.setDouble(2, c.getPrice());
				ps.setInt(3, c.getNumber());
				ps.execute();
				if(ps!=null){
		    		ps.close(); 		   		
		    	}
		    	if(con!=null){
		    		con.close();    		   		
		    	}
		    	
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}		   		   
			   
			   return true;
		   } 

}
